﻿using DAO.DAOUtils;
using DAO.IAuthorizationDAO;
using DTO.Authorization;
using DTO.DTOUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO.AuthorizationDAO
{
    public class RoleOnFunc : IRoleOnFunc
    {

        public bool Insert(DTO.Authorization.RoleOnFuncDTO roleOnFunc)
        {
            var parameters = GetListParameters(roleOnFunc);
            return SQLUtils.ExcuteNoneQuery("RoleOnFuncInsert", ref parameters);
        }

        public bool DeleteByRoleId(string roleId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleId, roleId));
            return SQLUtils.ExcuteNoneQuery("RoleOnFuncDeleteByRoleId", ref parameters);
        }

        public bool DeleteByFunc(string roleFunctionName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleFunctionName, roleFunctionName));
            return SQLUtils.ExcuteNoneQuery("RoleOnFuncDeleteByFunc", ref parameters);
        }

        public bool UpdateByParam(DTO.Authorization.RoleOnFuncDTO roleOnFunc, Boolean active)
        {
            var parameters = GetListParameters(roleOnFunc);
            parameters.Add(new Parameter("@active", active));
            return SQLUtils.ExcuteNoneQuery("RoleOnFuncUpdateByParam", ref parameters);

        }

        public System.Data.DataTable GetFunctionNameByRoleId(String roleId)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleId, roleId));
            return SQLUtils.ExcuteQuery("RoleOnFuncGetFunctionNameByRoleId", ref parameters);
        }

        public System.Data.DataTable GetRoleIdByFunctionName(String functionName)
        {
            var parameters = Parameter.CreateList(new Parameter(DTOConstant.RoleFunctionName, functionName));
            return SQLUtils.ExcuteQuery("RoleOnFuncGetRoleIdByFunctionName", ref parameters);
        }

        public System.Data.DataTable GetALL()
        {
            var parameters = Parameter.CreateList();
            return SQLUtils.ExcuteQuery("RoleOnFuncGetAll", ref parameters);
        }

        public List<Parameter> GetListParameters(RoleOnFuncDTO roleOnFunc)
        {
            return Parameter.CreateList(
                    new Parameter(DTOConstant.RoleId, roleOnFunc.RoleId),
                    new Parameter(DTOConstant.RoleFunctionName, roleOnFunc.FunctionName)
                );
        }
    }
}
